/*contains methods of grid class,which is basically a sudoku grid.
 * 
 */
package sudokusolver;
//import java.util.HashSet;
public class Grid {    
    Cell[][] grid;//that stores all the cell values.
    final static int NO_OF_ROWS=9;//number of rows
    final static int NO_OF_COLUMNS=9;//number of columns.
    public Grid() {//makes new grid.
        grid=new Cell[NO_OF_ROWS][NO_OF_COLUMNS];
    }
    public void printGrid() {//prints out the contents of a grid.
        for (int k = 0; k <Grid.NO_OF_ROWS; k++) {
            for (int l = 0; l <Grid.NO_OF_COLUMNS; l++) {
                int cur=grid[k][l].finalVal;
                if(cur!=0)System.out.print("["+cur+"]");//there is a value.
                else System.out.print("[*]");//empty cell.
            }
            System.out.println();
        }
        System.out.println("------------------------------");
    }
    public boolean isSolved() {//is grid completely filled up!
        for (int t = 0; t < NO_OF_ROWS; t++) {
            for (int u = 0; u < NO_OF_COLUMNS; u++) {
                if(grid[t][u].markup.size()!=1) return false;//this cell isn't
                //filled up.
            }
        }
        return true;
    }
    public void printMarkup() {
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < (Grid.NO_OF_COLUMNS+3) * (Grid.NO_OF_COLUMNS); i++) {
            s.append('-');
        }
        System.out.println(s);
        for (int k = 0; k <Grid.NO_OF_ROWS; k++) {
            for (int l = 0; l <Grid.NO_OF_COLUMNS; l++) {
                System.out.print(grid[k][l].getMarkupString() + " ");
            }
            System.out.println();
        }
        System.out.println(s);
    }
}
